/**
*
* minjs.Table class
* @class minjs.Table
* @inherits minjs.Element 
*/
minjs.Table = function() {	
	//var tbl = minjs.Element.create("table");
	minjs.Element.call(this, minjs.Element.create("table").getDOMElement());
	
	this.setClassName("minjs-Table");
	this.add(minjs.Element.create("thead"));
	this.add(minjs.Element.create("tbody"));
	this.add(minjs.Element.create("tfoot"));
	
	this.setBorder(0);
	this.setCellPadding(0);
	this.setCellSpacing(0);
}

minjs.Table.prototype = new minjs.Element();
minjs.Table.prototype.constructor = minjs.Table;

minjs.Table.prototype.insertRow = function(index){
	var row = this.getDOMElement().tBodies[0].insertRow(index);
	return new minjs.Table.Row(row);
}

minjs.Table.prototype.deleteRow = function(index){
	this.getDOMElement().tBodies[0].deleteRow(index);
}

minjs.Table.prototype.getRow = function(index){
	var row = this.getDOMElement().tBodies[0].rows[index];
	return new minjs.Table.Row(row);
}

minjs.Table.prototype.getRowCount = function(){
	return this.getDOMElement().tBodies[0].rows.length;
}

minjs.Table.prototype.insertHeaderRow = function(index){
	var row = this.getDOMElement().tHead.insertRow(index);
	return new minjs.Table.Row(row);
}

minjs.Table.prototype.deleteHeaderRow = function(index){
	this.getDOMElement().tHead.deleteRow(index);
}

minjs.Table.prototype.getHeaderRow = function(index){
	var row = this.getDOMElement().tHead.rows[index];
	return new minjs.Table.Row(row);
}

minjs.Table.prototype.getHeaderRowCount = function(){
	return this.getDOMElement().tHead.rows.length;
}

minjs.Table.prototype.insertFooterRow = function(index){
	var row = this.getDOMElement().tFoot.insertRow(index);
	return new minjs.Table.Row(row);
}

minjs.Table.prototype.deleteFooterRow = function(index){
	this.getDOMElement().tFoot.deleteRow(index);
}

minjs.Table.prototype.getFooterRow = function(index){
	var row = this.getDOMElement().tFoot.rows[index];
	return new minjs.Table.Row(row);
}

minjs.Table.prototype.getFooterRowCount = function(){
	return this.getDOMElement().tFoot.rows.length;
}

minjs.Table.prototype.applyRowFormatter = function(formatter){
	var rows = this.getDOMElement().tBodies[0].rows;
	for(var i in rows){
		//formatter.formatRow(rows[i]);
		formatter.formatRow(new minjs.Table.Row(rows[i]));
	}
}

minjs.Table.prototype.setBorder = function(width){
	this.getDOMElement().border = width;
}

minjs.Table.prototype.getBorder = function(){
	return this.getDOMElement().border;
}

minjs.Table.prototype.setCellPadding = function(padding){
	this.getDOMElement().cellPadding = padding;
}

minjs.Table.prototype.getCellPadding = function(){
	return this.getDOMElement().cellPadding;
}

minjs.Table.prototype.setCellSpacing = function(spacing){
	this.getDOMElement().cellSpacing = spacing;
}

minjs.Table.prototype.getCellSpacing = function(){
	return this.getDOMElement().cellSpacing;
}

/**
*
* minjs.Table.RowFormatter class
* @class minjs.Table.RowFormatter
*/
minjs.Table.RowFormatter = {
	createOddEvenFormatter: function(){
		var rownum = 0;
		return {
			formatRow: function(row){
				//row.setPrimaryClassName((++rownum % 2) ? "minjs-Table-oddRow" : "minjs-Table-evenRow");
				row.setClassName((++rownum % 2) ? "minjs-Table-oddRow" : "minjs-Table-evenRow");
			}
		};		
	}
};

/**
*
* minjs.Table.Row class
* @class minjs.Table.Row
* @inherits minjs.Element 
*/
minjs.Table.Row = function(rowElement){
	minjs.Element.call(this, rowElement);
}

minjs.Table.Row.prototype = new minjs.Element();
minjs.Table.Row.prototype.constructor = minjs.Table.Row;

minjs.Table.Row.prototype.insertCell = function(cellIndex){
	var cell = this.getDOMElement().insertCell(cellIndex);
	return new minjs.Table.Cell(cell);
}

minjs.Table.Row.prototype.deleteCell = function(cellIndex){
	this.getDOMElement().deleteCell(cellIndex);
}

minjs.Table.Row.prototype.getCell = function(cellIndex){
	var cell = this.getDOMElement().cells[cellIndex];
	return new minjs.Table.Cell(cell);
}

/**
*
* minjs.Table.Cell class
* @class Table.Cell
* @inherits Element 
*/
minjs.Table.Cell = function(cellElement){
	minjs.Element.call(this, cellElement);
}

minjs.Table.Cell.prototype = new minjs.Element();
minjs.Table.Cell.prototype.constructor = minjs.Table.Cell;

minjs.Table.Cell.prototype.setColSpan = function(span){
	this.getDOMElement().colSpan = span;
}

minjs.Table.Cell.prototype.getColSpan = function(){
	return this.getDOMElement().colSpan;
}

minjs.Table.Cell.prototype.setRowSpan = function(span){
	this.getDOMElement().rowSpan = span;
}

minjs.Table.Cell.prototype.getRowSpan = function(){
	return this.getDOMElement().rowSpan;
}
















